/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package plan.mobile;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import mobile.Call;
import mobile.Message;
import mobile.MobileConsumption;
import plan.Plan;
import turnover.Consumption;

/**
 *
 * @author Alberto
 */
public class Vodafone_Super_90x1_Contrato extends Plan {

    private double startQuote = 0;
    private double minuteCost = 19.9d;
    private double messageCost = 0.15d;

    public Vodafone_Super_90x1_Contrato() {
        super.setName("Vodafone Super 90 x 1 de Contrato");
        getSavesNoCompatibles().add("save.Orange_Bono_ahorroSMS");
    }

    public double getStartQuote() {
        return startQuote;
    }

    @Override
    public double getCost(Consumption consumption) {
        double total = 0d;
        MobileConsumption mc = (MobileConsumption) consumption;
        List<Long> numList = new LinkedList();
        long durationMax = 1000 * 60;
        double establecimiento = 34.9d;
        long duration = 0;

        Iterator it = mc.getCallList().listIterator();
        while (it.hasNext()) {
            Call c = (Call) it.next();


            if (c.isSpecial()) {
                total += c.getCost();
            } else if (!(this.over90(c) && this.overDurationMax(durationMax, duration))) {
                duration += c.getDuration().changeSeconds();
                if(this.overDurationMax(durationMax, duration)){
                    total += this.minuteCost + establecimiento;
                }
                if (!numList.contains(c.getMobile())) {
                    numList.add(c.getMobile());
                }
            }else if (this.over90(c) || this.overDurationMax(durationMax, duration)) {
                total += c.getDuration().changeSeconds() - 5400 * this.minuteCost / 60;
                duration += 5400;
                if (!numList.contains(c.getMobile())) {
                    numList.add(c.getMobile());
                }
            } else {
                total += c.getDuration().changeSeconds() * this.minuteCost / 60;
            }
        }
        it = mc.getMessList().listIterator();
        while (it.hasNext()) {
            Message m = (Message) it.next();
            if (m.isSpecial()) {
                total += m.getCost();
            } else {
                total += this.messageCost;
            }
        }

        if (total<12d){
            total = 12d;
        }

        total += total * 0.16d;
        return total;
    }


       
    public boolean over90(Call c) {
        return c.getDuration().changeSeconds() > 5400;
    }


    public double getMessageCost() {
        return messageCost;
    }

    public double getMinuteCost() {
        return minuteCost;
    }
    private boolean overDurationMax(long durationMax, long duration) {
        return durationMax <= duration;
    }
}



    

    